Imports Microsoft.VisualBasic
Imports System
Imports System.Collections
Imports System.Configuration
Imports System.Data
Imports System.Linq
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Xml.Linq
Imports System.Collections.Generic
Imports facebook.web
Imports System.Web.Configuration
Imports facebook
Imports facebook.Schema
Imports facebook.Utility

Namespace FBMLSample.handlers
	Partial Public Class otherPublishHandler
		Inherits CanvasFBMLBasePage
		Protected json As String = String.Empty
		Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As EventArgs)
			Me.RequireLogin = True
		End Sub
		Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
			Dim basePage = New BasePage()
			Dim moods = basePage.getOtherMoods()
			If (Not String.IsNullOrEmpty(Request.Params("method"))) AndAlso Request.Params("method") = "publisher_getFeedStory" Then
				'TODO: need to figure out how to pull picked out of this
				Dim picked = 0 'int.Parse(Request.Params["app_params"]);
                Dim canvas = String.Format("http://apps.facebook.com/{0}/mysmiles.aspx", suffix)

                Dim templateDataDict = New Dictionary(Of String, String)
                templateDataDict.Add("emote", moods.ElementAt(picked).Value)
                templateDataDict.Add("emoteaction", moods.ElementAt(picked).Value)
                Dim templateData = JSONHelper.ConvertToJSONAssociativeArray(templateDataDict)

                Dim feedDict = New Dictionary(Of String, String)
                feedDict.Add("template_id", basePage.FeedTemplate2.ToString())
                feedDict.Add("template_data", templateData)
                Dim feed = JSONHelper.ConvertToJSONAssociativeArray(feedDict)

                Dim contentDict = New Dictionary(Of String, String)
                contentDict.Add("feed", feed)
                Dim content = JSONHelper.ConvertToJSONAssociativeArray(contentDict)

                Dim dataDict = New Dictionary(Of String, String)
                dataDict.Add("method", "publisher_getFeedStory")
                dataDict.Add("content", content)
                Dim data = JSONHelper.ConvertToJSONAssociativeArray(dataDict)

				json = data
			ElseIf (Not String.IsNullOrEmpty(Request.Params("method"))) AndAlso Request.Params("method") = "publisher_getInterface" Then
				'TODO: need to figure out how to pull picked out of this
				Dim picked = 0 'int.Parse(Request.Params["app_params"]);
				Dim fbml = FBMLControlRenderer.RenderFBML(Of String)(String.Format("~/controls/PublisherHeader.ascx"),callback)
                fbml += String.Format("<form>{0}<input type=""hidden"" id=""picked"" name=""picked"" value=""-1""></form>", basePage.BuildEmoticonGrid(moods, callback, suffix, False))

                Dim contentDict = New Dictionary(Of String, String)
                contentDict.Add("fbml", fbml)
                contentDict.Add("publishEnabled", "false")
                contentDict.Add("commentEnabled", "false")
                Dim content = JSONHelper.ConvertToJSONAssociativeArray(contentDict)

                Dim dataDict = New Dictionary(Of String, String)
                dataDict.Add("method", "publisher_getInterface")
                dataDict.Add("content", content)
                Dim data = JSONHelper.ConvertToJSONAssociativeArray(dataDict)

				json = data
			Else
				Throw New Exception("no smile picked")
			End If
		End Sub
	End Class
End Namespace
